<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="inp">
    <div class="txt"></div>
</body>
<script>
    const obj={}
    const inp=document.querySelector('#inp')

    Object.defineProperty(obj,'prop',{
        get() {
            return val;
        },
        set(newV) {
            console.log('新值：',newV)
            val=newV;
            document.querySelector('.txt').textContent=val;
        }
    })

    inp.addEventListener('keyup',function(e) {
        console.log(e.target.value)
        obj.prop=e.target.value
    },false)
</script>
</html>